Ext.define('PJ.view.codtrainingprogram.List', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.codtrainingprogramList'],
    requires: ['AM.default.DefaultSearchForm',
               'AM.default.DateTime', 
               'AM.default.DefaultDateField',
               'AM.default.DefaultDoubleDateField',
               'AM.default.jsonp.DefaultLoadJsonp',//jsonp加载数据
		       'AM.default.DefaultActiveStateCombo',
		       'PJ.view.quotamanagement.PlanPlacesList',//计划名额
		       'PJ.view.quotamanagement.AdjustTheQuotaList',
		       'AM.default.DateMonth',
		       'PJ.view.codtrainingprogram.UnitsIssuedList',//下发单位
		       'PJ.view.trainingprogram.UnitsIssuedList',//已下发单位
		       'PJ.view.trainingprogram.FeedbackList'//已反馈信息
               ],
    initComponent: function(){
    	var me= this;
    	this.columns = [{
    		header: '计划编号',
    		dataIndex: 'applyNum',
    		width: 120,
    		renderer: function(value, meta, record){
    			return value;
    		}
    	},{
            header: '培训班名称',
            dataIndex: 'className',
            flex: 1,
            minWidth: 120,
    		renderer: function(value, metaData, record){
    			metaData.style = "white-space:normal;cursor: pointer;color:blue;";
    			metaData.tdAttr = "data-qtip='" + value + "' classId=" + record.get("planId") + " versionState=" + record.get("versionState");
    			return value;
    		},
    		listeners: {
    			click: function(g, clm){
    				var classId = clm.getAttribute("classId");
    				var versionState = clm.getAttribute("versionState");
    				if(versionState == "2"){
    					win = Ext.create('PJ.view.codtrainingprogram.NoneVersionView', {
        					title: "查看培训计划",
        					flag:4,
        					grid: me,
        					isDisable:false,
        					planId:classId,
        		        	isReadOnly:true
        				}).show();
        				var actionName = "load";
        				if(gj_onlineLearning_constant.loadType == "jsonp"){
        					actionName = "loadJsonp";
        				}
        				win.down("form").getForm().doAction(actionName,{
        					url:me.store.preUpdateUrl,
        					params:{
        						planId: classId
        					},
        					success:function(f,action){
        						var data = action.response.responseText;
        	        			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
        	        			var form = win.down('form');	 
        	        			var baseForm = form.getForm();
        					}
        				});
    				}else if(versionState == "1"){
        				win = Ext.create('PJ.view.codtrainingprogram.View', {
        					title: "查看培训计划",
        					flag:4,
        					grid: me,
        					isDisable:false,
        					planId:classId,
        		        	isReadOnly:true
        				}).show();
        				var actionName = "load";
        				if(gj_onlineLearning_constant.loadType == "jsonp"){
        					actionName = "loadJsonp";
        				}
        				win.down("form").getForm().doAction(actionName,{
        					url:me.store.preUpdateUrl,
        					params:{
        						planId: classId
        					},
        					success:function(f,action){
        						var data = action.response.responseText;
        	        			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
        	        			var form = win.down('form');	 
        	        			var baseForm = form.getForm();
        	        			if(!json.data.classNameState){
//        		    				baseForm.findField("classNameOld").setFieldLabel("<span style='color:red;'>专题名称:</span>");
        		    				baseForm.findField("classNameNew").setFieldLabel("<span style='color:red;'>培训班名称:</span>");
        		    			}
        		    			if(!json.data.applyNumState){
//        		    				baseForm.findField("applyNumOld").setFieldLabel("<span style='color:red;'>计划申请编号:</span>");
        		    				baseForm.findField("applyNumNew").setFieldLabel("<span style='color:red;'>计划申请编号:</span>");
        		    			}
        		    			if(!json.data.undertakeNameState){
//        		    				baseForm.findField("undertakeNameOld").setFieldLabel("<span style='color:red;'>承办部委:</span>");
        		    				baseForm.findField("undertakeNameNew").setFieldLabel("<span style='color:red;'>承办部委:</span>");
        		    			}
        		    			if(!json.data.jointNameState){
//        		    				baseForm.findField("jointNameOld").setFieldLabel("<span style='color:red;'>合办部委:</span>");
        		    				baseForm.findField("jointNameNew").setFieldLabel("<span style='color:red;'>合办部委:</span>");
        		    			}
        		    			/*if(!json.data.planDateState){
//        		    				baseForm.findField("planDateOld").setFieldLabel("<span style='color:red;'>计划时间:</span>");
        		    				baseForm.findField("planDateNew").setFieldLabel("<span style='color:red;'>计划时间:</span>");
        		    			}*/
        		    			if(!json.data.startPlanDateStateStr){
        		    				baseForm.findField("startPlanDateNewStr").setFieldLabel("<span style='color:red;'>计划开始时间:</span>");
        		    			}
        		    			if(!json.data.endPlanDateStateStr){
        		    				baseForm.findField("endPlanDateNewStr").setFieldLabel("<span style='color:red;'>计划结束时间:</span>");
        		    			}
        		    			if(!json.data.planDayState){
//        		    				baseForm.findField("planDayOld").setFieldLabel("<span style='color:red;'>学制（天）:</span>");
        		    				baseForm.findField("planDayNew").setFieldLabel("<span style='color:red;'>学制（天）:</span>");
        		    			}
        		    			if(!json.data.classObjectiveState){
//        		    				baseForm.findField("classObjectiveOld").setFieldLabel("<span style='color:red;'>办班目的:</span>");
        		    				baseForm.findField("classObjectiveNew").setFieldLabel("<span style='color:red;'>办班目的:</span>");
        		    			}
        		    			if(!json.data.classValuesState){
//        		    				baseForm.findField("classValuesOld").setFieldLabel("<span style='color:red;'>培训内容:</span>");
        		    				baseForm.findField("classValuesNew").setFieldLabel("<span style='color:red;'>培训内容:</span>");
        		    			}
        		    			if(!json.data.trainingObjectState){
//        		    				baseForm.findField("trainingObjectOld").setFieldLabel("<span style='color:red;'>调训对象:</span>");
        		    				baseForm.findField("trainingObjectNew").setFieldLabel("<span style='color:red;'>调训对象:</span>");
        		    			}
        		    			if(!json.data.trainingAddressState){
//        		    				baseForm.findField("trainingAddressOld").setFieldLabel("<span style='color:red;'>培训地点:</span>");
        		    				baseForm.findField("trainingAddressNew").setFieldLabel("<span style='color:red;'>培训地点:</span>");
        		    			}
        		    			if(!json.data.linkManState){
//        		    				baseForm.findField("linkManOld").setFieldLabel("<span style='color:red;'>联系人:</span>");
        		    				baseForm.findField("linkManNew").setFieldLabel("<span style='color:red;'>联系人:</span>");
        		    			}
        		    			if(!json.data.linkModeState){
//        		    				baseForm.findField("linkModeOld").setFieldLabel("<span style='color:red;'>联系电话:</span>");
        		    				baseForm.findField("linkModeNew").setFieldLabel("<span style='color:red;'>联系电话:</span>");
        		    			}
        		    			if(!json.data.faxState){
//        		    				baseForm.findField("linkModeOld").setFieldLabel("<span style='color:red;'>传真:</span>");
        		    				baseForm.findField("faxNew").setFieldLabel("<span style='color:red;'>传真:</span>");
        		    			}
        					}
        				});
    				}
    			}
    		}
        },{
            header: '计划调训人数',
            dataIndex: 'planNum',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value;
            }
        },{
        	header: '学制（天）',
        	dataIndex: 'planDay',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value;
            }
        }/*,{
        	header: '计划时间',
        	dataIndex: 'planDate',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value;
            }
        }*/,{
        	header: '计划开始时间',
        	dataIndex: 'startPlanDateStr',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value;
            }
        },{
        	header: '计划结束时间',
        	dataIndex: 'endPlanDateStr',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value;
            }
        },{
            header: '审核状态',
            dataIndex: 'auditState',
            width: 80,
            renderer: function(v, metaData, record){
            	metaData.tdAttr = "classId=" + record.get("planId") + " auditState=" + v + " rejectReason=" + record.get("rejectReason");
                if (v == 2) {
                	metaData.style = "cursor: pointer;color:blue;";
                    return '建议修改';
                }
                else if(v == 1) {
                    return '审核通过';
                }
                else if(v == 3) {
                    return '待审核';
                }else if(v == 4) {
                	return '未上报';
                }else if(v == 5){
                	metaData.style = "color:red;";
                	return '审核否决';
                }
            },
    		listeners: {
    			click: function(g, clm){
    				var approvalStatus = clm.getAttribute("auditState");
    				var classId = clm.getAttribute("classId");
    				var rejectReason = clm.getAttribute("rejectReason");
    				if(approvalStatus != 2){
    					return;
    				}else{
    					win = Ext.create('PJ.view.codtrainingprogram.AuditOpinionEdit', {
        					title: "查看建议修改意见",
        					isView:true
        				}).show();
    					var form = win.down('form');	 
	        			var baseForm = form.getForm();
	        			rejectReason = decodeURI(rejectReason);
        				baseForm.findField("rejectReason").setValue(rejectReason);
    				}
    			}
    		}
        },{
            header: '下发状态（反馈数/下发数）',
            dataIndex: 'issuedState',
            renderer: function(v, metaData, record){
            	metaData.tdAttr = "classId=" + record.get("planId") + " issuedState=" + v;
                if(v == 1 || v == 3){
             	   metaData.style = "cursor: pointer;color:blue;";
                }
                return record.get("issuedStr");
            },
            width: 155,
    		listeners: {
    			click: function(g, clm){
    				var issuedState = clm.getAttribute("issuedState");
    				var classId = clm.getAttribute("classId");
    				if(issuedState == 1){
    					Ext.create('AM.default.DefaultWindowView', {
    			            title: "查看已下发单位",
    			            height:350,
    			            width: 250,
    			            grid: me,
    			            classId:classId,
    			            items: [{
    			                xtype: 'unitsIssuedList',
    			                planId:classId,
    			                isView: true
    			            }],
    			            listeners: {
    			            	close: function(){
    			            		me.getStore().load();
    			            	}
    			            }
    			        });
    				}else if(issuedState == 3){
    					Ext.create('AM.default.DefaultWindowView', {
    			            title: "查看反馈意见",
    			            height:450,
    			            width: 550,
    			            grid: me,
    			            planId:classId,
    			            items: [{
    			                xtype: 'feedbackList',
    			                planId:classId,
    			                isView: true
    			            }],
    			            listeners: {
    			            	close: function(){
    			            		me.getStore().load();
    			            	}
    			            }
    			        });
    				}else {
    					return;
    				}
    			}
    		}
        },{
            header: '发布状态',
            dataIndex: 'publishState',
            renderer: function(v, metaData, record){
                if (v == 2) {
                    return '<span style="color:red;">' + '未发布' + '</span>';
                }
                else if(v == 1) {
                    return '<span style="color:green;">' + '已发布' + '</span>';
                }
            },
            width: 70
        }];
    	
        this.store = Ext.create('PJ.'+ prototype +'.codtrainingprogram.List',{
        	isLoad: true
        });
        this.callParent(arguments);
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
    },
	//修改
	onUpdateClick:function(){
		var me = this;
		var record=me.getSelectionModel().getSelection();
    	var classId = record[0].get("planId");
		if(this.getSelectionModel().getCount() > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '操作时只可选中一条记录！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
        }
		if(record[0].get("t.publishState")==1){
			Ext.Msg.show({
                title: '提示',
                msg: '已发布的信息不允许再进行修改操作!',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
		}
        win = Ext.create('PJ.view.trainingprogram.Edit', {
        	title: "更新培训班",
            flag:2,
        	grid: me,
        	isDisable:true,
        	classId:classId,
        	isReadOnly:false
        }).show();
        var actionName = "load";
		if(gj_onlineLearning_constant.loadType == "jsonp"){
			actionName = "loadJsonp";
		}
		win.down("form").getForm().doAction(actionName,{
    		url:me.store.preUpdateUrl,
    		params:{
    			classId: classId
    		},
    		success:function(f,action){
    			var data = action.response.responseText;
    			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
    			var form = win.down('form');	 
    			var baseForm = form.getForm();
    			baseForm.findField("classNum").setValue(json.data.classNum);
    			baseForm.findField("classNum_").setValue(json.data.classNum);
    		}
    	});
	},
	/**
	 * 培训计划审核
	 */
	onTrainingProgramAuditClick: function(){
		var me = this;
		var record=me.getSelectionModel().getSelection();
    	var classId = record[0].get("planId");
    	if(this.getSelectionModel().getCount() > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '操作时只可选中一条记录！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
        }
    	if(record[0].get("auditState") == 5){
    		Ext.Msg.show({
                title: '提示',
                msg: '审核否决的信息不允许再进行任何操作!',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
    	}
    	if(record[0].get("publishState")!=2){
			Ext.Msg.show({
				title: '提示',
				msg  : '只允许对未发布的数据执行审核操作!',
				icon :Ext.Msg.WARNING,
				buttons:Ext.Msg.OK
			});
			return;
		}
		var win = null;
		var versionState = record[0].get("versionState");
		if(versionState == "2"){
			win = Ext.create('PJ.view.codtrainingprogram.FirstAudit', {
	        	title: "培训计划审核",
	            flag:2,
	        	grid: me,
	        	isDisable:true,
	        	planId:classId,
	        	isReadOnly:true,
	        	versionState: false
	        }).show();
    	}else if(versionState == "1") {
    		win = Ext.create('PJ.view.codtrainingprogram.TrainingProgramAudit', {
            	title: "培训计划审核",
                flag:2,
            	grid: me,
            	isDisable:true,
            	planId:classId,
            	isReadOnly:true,
            	versionState: true
            }).show();
    	}
		var actionName = "load";
		if(gj_onlineLearning_constant.loadType == "jsonp"){
			actionName = "loadJsonp";
		}
		win.down("form").getForm().doAction(actionName,{
    		url:me.store.preUpdateUrl,
    		params:{
    			planId: classId
    		},
    		success:function(f,action){
    			var data = action.response.responseText;
    			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
    			var form = win.down('form');	 
    			var baseForm = form.getForm();
    			if(!json.data.classNameState && versionState == "1"){
    				//baseForm.findField("classNameOld").setFieldLabel("<span style='color:red;'>专题名称:</span>");
    				baseForm.findField("classNameNew").setFieldLabel("<span style='color:red;'>培训班名称:</span>");
    			}
    			if(!json.data.applyNumState && versionState == "1"){
    				//baseForm.findField("applyNumOld").setFieldLabel("<span style='color:red;'>计划申请编号:</span>");
    				baseForm.findField("applyNumNew").setFieldLabel("<span style='color:red;'>计划申请编号:</span>");
    			}
    			if(!json.data.undertakeNameState && versionState == "1"){
    				//baseForm.findField("undertakeNameOld").setFieldLabel("<span style='color:red;'>承办部委:</span>");
    				baseForm.findField("undertakeNameNew").setFieldLabel("<span style='color:red;'>承办部委:</span>");
    			}
    			if(!json.data.jointNameState && versionState == "1"){
    				//baseForm.findField("jointNameOld").setFieldLabel("<span style='color:red;'>合办部委:</span>");
    				baseForm.findField("jointNameNew").setFieldLabel("<span style='color:red;'>合办部委:</span>");
    			}
    			/*if(!json.data.planDateState && versionState == "1"){
    				//baseForm.findField("planDateOld").setFieldLabel("<span style='color:red;'>计划时间:</span>");
    				baseForm.findField("planDateNew").setFieldLabel("<span style='color:red;'>计划时间:</span>");
    			}*/
    			if(!json.data.startPlanDateStateStr && versionState == "1"){
    				//baseForm.findField("planDateOld").setFieldLabel("<span style='color:red;'>计划时间:</span>");
    				baseForm.findField("startPlanDateNewStr").setFieldLabel("<span style='color:red;'>计划开始时间:</span>");
    			}
    			if(!json.data.endPlanDateStateStr && versionState == "1"){
    				//baseForm.findField("planDateOld").setFieldLabel("<span style='color:red;'>计划时间:</span>");
    				baseForm.findField("endPlanDateNewStr").setFieldLabel("<span style='color:red;'>计划结束时间:</span>");
    			}
    			if(!json.data.planDayState && versionState == "1"){
    				//baseForm.findField("planDayOld").setFieldLabel("<span style='color:red;'>学制（天）:</span>");
    				baseForm.findField("planDayNew").setFieldLabel("<span style='color:red;'>学制（天）:</span>");
    			}
    			if(!json.data.classObjectiveState && versionState == "1"){
    				//baseForm.findField("classObjectiveOld").setFieldLabel("<span style='color:red;'>办班目的:</span>");
    				baseForm.findField("classObjectiveNew").setFieldLabel("<span style='color:red;'>办班目的:</span>");
    			}
    			if(!json.data.classValuesState && versionState == "1"){
    				//baseForm.findField("classValuesOld").setFieldLabel("<span style='color:red;'>培训内容:</span>");
    				baseForm.findField("classValuesNew").setFieldLabel("<span style='color:red;'>培训内容:</span>");
    			}
    			if(!json.data.trainingObjectState && versionState == "1"){
    				//baseForm.findField("classObjectiveOld").setFieldLabel("<span style='color:red;'>调训对象:</span>");
    				baseForm.findField("trainingObjectNew").setFieldLabel("<span style='color:red;'>调训对象:</span>");
    			}
    			if(!json.data.trainingAddressState && versionState == "1"){
    				//baseForm.findField("trainingAddressOld").setFieldLabel("<span style='color:red;'>培训地点:</span>");
    				baseForm.findField("trainingAddressNew").setFieldLabel("<span style='color:red;'>培训地点:</span>");
    			}
    			if(!json.data.linkManState && versionState == "1"){
    				//baseForm.findField("linkManOld").setFieldLabel("<span style='color:red;'>联系人:</span>");
    				baseForm.findField("linkManNew").setFieldLabel("<span style='color:red;'>联系人:</span>");
    			}
    			if(!json.data.linkModeState && versionState == "1"){
    				//baseForm.findField("linkModeOld").setFieldLabel("<span style='color:red;'>联系电话:</span>");
    				baseForm.findField("linkModeNew").setFieldLabel("<span style='color:red;'>联系电话:</span>");
    			}
    			if(!json.data.faxState && versionState == "1"){
    				//baseForm.findField("faxOld").setFieldLabel("<span style='color:red;'>传真:</span>");
    				baseForm.findField("faxNew").setFieldLabel("<span style='color:red;'>传真:</span>");
    			}
    		}
    	});
	},
	//建议修改
	onBackClick: function(){
		var me=this;
		var store=me.getStore();
		var records=me.getSelectionModel().getSelection();
		var plans= new Array();
		Ext.Array.each(records,function(name,index){
			classIds.push(name.get('planId'));
		});
		for(var i=0;i<records.length;i++){
			if(records[i].get("auditState")!=3){
				Ext.Msg.show({
					title: '提示',
					msg  : '只允许对待审核的数据执行建议修改操作!',
					icon :Ext.Msg.WARNING,
					buttons:Ext.Msg.OK
				});
				return;
			}
		}
		Ext.create('PJ.view.codtrainingprogram.AuditOpinionEdit',{
        	title: "建议修改",
            flag:1,
            classIds: classIds,
        	grid: me,
        	isView: false
        });
	},
	//上传参训通知
	onImportClick: function(){
		var me = this;
		var records = me.getSelectionModel().getSelection();
		if(records.length > 1){
			Ext.Msg.show({
				title: '提示',
				msg: '只允许操作一条数据！',
				icon: Ext.Msg.WARNING,
				buttons: Ext.Msg.OK
			});
			return;
		}
    	Ext.create("PJ.view.trainingmanagement.UploadInfo", {
			title: "上传参训通知",
			height: 140,
			width: 350,
			grid: me,
			classId: records[0].get('planId')
		}).show();
    },
  //导入名额
    onImportquotasClick: function(){
		var me = this;
		var records = this.getSelectionModel().getSelection();
    	Ext.create("PJ.view.codtrainingprogram.BatchImportEdit", {
			title: "批量更新培训计划",
			height: 110,
			width: 380,
			grid: me
		}).show();
    },
    /**
     * 导入培训班信息
     */
    onImportCourseInformationClick: function(){
    	var me = this;
		var records=me.getSelectionModel().getSelection();
        if(records == null || records.length == 0){
        	Orchid.alert("提示","请至少选择一个培训班！");
        	return;
        }
        if(records.length>1){
        	Orchid.alert("提示","只允许选择一个培训班！");
        	return;
        }
    	var applyNum = records[0].get("applyNum");
    	Ext.create("PJ.view.codtrainingprogram.CourseInformation", {
			title: "导入培训班信息",
			height: 140,
			width: 380,
			applyNum:applyNum,
			grid: me
		}).show();
    },
    /**
     * 下发培训计划
     */
    onPlanplacesClick: function(){
		var me = this;
		var records = this.getSelectionModel().getSelection();
		var planIds=new Array();
		for(i in records){
			planIds.push(records[i].get("planId"));
			if(records[i].get("auditState") == 5){
	    		Ext.Msg.show({
	                title: '提示',
	                msg: '审核否决的信息不允许再进行任何操作!',
	                icon: Ext.Msg.WARNING,
	                buttons: Ext.Msg.OK
	            });
	        	return;
	    	}
	        if(records[i].get("publishState")==1){
	        	 Ext.Msg.show({
	                 title: '提示',
	                 msg: '已发布计划不允许进行下发！',
	                 icon: Ext.Msg.WARNING,
	                 buttons: Ext.Msg.OK
	             });
	         	return;
	        }
		}
//		var classId = record[0].get("planId");
		
//        if(this.getSelectionModel().getCount() > 1){
//            Ext.Msg.show({
//                title: '提示',
//                msg: '操作时只可选中一条记录！',
//                icon: Ext.Msg.WARNING,
//                buttons: Ext.Msg.OK
//            });
//        	return;
//        }
		
        
        Ext.create('AM.default.DefaultWindowView', {
            title: "下发培训计划",
            height:350,
            width: 400,
            grid: me,
            planIds:planIds,
            items: [{
            	xtype: "container",
    			border: false,
    			layout: 'column',
    			items: [{
    				xtype: "textareafield",
    				fieldLabel: '附加消息',
    				name: 'opinions',
    				labelAlign: 'right',
    				labelWidth: 65,
    				columnWidth: .98,
    				allowBlank: false,
    				padding: '5 0 0 0',
    				maxLength: 300,
    				margin: '0 0 6 0'
    			},{
                    xtype: 'coprunitsIssuedList',
                    planId: records[0].get("planId"),
                    columnWidth: 1,
                    isView: false,
                    height: 210,
    				margin: '0 0 0 10'
                }]
            }],
            buttons: [{
                text: '确定',
                handler: function(button, event){
                    var win = button.up('window');
                    var opinions = win.down("textareafield").getValue();
                    var grid = win.down("coprunitsIssuedList");
                    var records=grid.getSelectionModel().getSelection();
                    if(records == null || records.length == 0){
                    	Orchid.alert("提示","请至少选择一个要下发的单位！");
                    	return;
                    }
                    var unitIds = new Array();
                    for(i in records){
                    	unitIds.push(records[i].get("deptId"));
                    }
                    if(gj_onlineLearning_constant.loadType == "jsonp"){
	  					  var store1 = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
	                    		loadType: gj_onlineLearning_constant.loadType,
	                            url: me.store.issuedATrainingPlanUrl,
	                    		  extraParams: {
	                    			  DeptIds: unitIds,
	                    			  searchPlanIds: planIds,
	                    			  opinions: opinions
	                            }
	                    	});
	                    	store1.load(function(rec, operation, success){
	                    		if(success){
	                                Ext.Msg.alert('消息', '下发成功！', function(){
	                                    var store = me.getStore();
	                                    store.load();
	                                    win.close();
	                                });
	                            }else{
	                                Ext.Msg.alert('消息', operation.error);
	                            }
	                    	});
	  				  }else{
	  					  Ext.Ajax.request({
	  						  url:me.store.issuedATrainingPlanUrl,
	  						  params: {
	  							  DeptIds: unitIds,
                    			  searchPlanIds: planIds,
                    			  opinions: opinions
                            },
	  						  success:function(response){
	  							  var data=response.responseText;
	  							  var json=Ext.decode(data,true);
	  							  if(json.success){
	  								  Orchid.alert('提示','下发成功!',function(){
	  									var store = me.getStore();
	  									  store.load();
	  									  win.close();
	  								  });
	  							  }else{
	  								  Orchid.alert('提示',json.msg);
	  							  }
	  						  }
	  					  });
	  				  }
                }
            }, {
                text: '关闭',
                scope: this,
                handler: function(button, event){
                    var win = button.up('window');
                    win.close();
                }
            }],
            listeners: {
            	close: function(){
            		me.getStore().load();
            	}
            }
        });
	},
	/**
     * 调整名额
     */
    onAdjustTheQuotaClick: function(){
		var me = this;
		var record = this.getSelectionModel().getSelection();
        if(this.getSelectionModel().getCount() > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '操作时只可选中一条记录！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
        }
		Ext.create('AM.default.DefaultWindowView', {
            title: "调整名额",
            height:550,
            width: 650,
            grid: me,
            classId:record[0].get("planId"),
            items: [{
                xtype: 'adjustTheQuotaList'
                    }],
            buttons: [{
                text: '确定',
                scope: this,
                handler: function(button){
                	button.up('window').down('adjustTheQuotaList').sub();
                }
            },{
                text: '关闭',
                scope: this,
                handler: function(button){
                	button.up('window').close();
                }
            }],
            listeners: {
            	close: function(){
            		me.getStore().load();
            	}
            }
        });
	},
	/**
	 * 发布培训计划
	 */
	onPostTrainingProgramClick: function(){
		var me=this;
		var store=me.getStore();
		var records=me.getSelectionModel().getSelection();
		if(this.getSelectionModel().getCount() > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '操作时只可选中一条记录！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
        }
		for(var i=0;i<records.length;i++){
			if(records[i].get("auditState") == 5){
	    		Ext.Msg.show({
	                title: '提示',
	                msg: '审核否决的信息不允许再进行任何操作!',
	                icon: Ext.Msg.WARNING,
	                buttons: Ext.Msg.OK
	            });
	        	return;
	    	}
			if(records[i].get("auditState") !=1&&records[i].get("auditState") !=5){
				Ext.Msg.show({
					title: '提示',
					msg  : '只允许发布审核通过的培训计划!',
					icon :Ext.Msg.WARNING,
					buttons:Ext.Msg.OK
				});
				return;
			}
			if(records[i].get("publishState") ==1){
				Ext.Msg.show({
					title: '提示',
					msg  : '已发布的数据不允许再次发布!',
					icon :Ext.Msg.WARNING,
					buttons:Ext.Msg.OK
				});
				return;
			}
		};
		Ext.Msg.confirm({
			title:'提示',
			msg:'您确定要发布此培训计划吗?',
			icon:Ext.Msg.WARNING,
			buttons:Ext.Msg.OKCANCEL,
			fn:function(id){
				if(id=='ok'){
					var classIds= new Array();
					Ext.Array.each(records,function(name,index){
						classIds.push(name.get('planId'));
					});
					Ext.Ajax.request({
						  url:me.store.autoClassNumUrl,
						  params: {
              			  searchPlanId: classIds,
                      },
                      success:function(response){
							  var data=response.responseText;
							  var json=Ext.decode(data,true);
							  Ext.create('PJ.view.codtrainingprogram.ConfirmationNumber',{
						        	title: "请确认培训班编号",
						        	grid: me,
						        	searchPlanIds: classIds,
						        	classNum:json.data.classNum
						        });
						  }
					  });
				}
			}
		});
	},
    //预览
    listeners: {
		selectionchange: function(selModel, selected){
//            this.down('#' + this.oldId + "Next").setDisabled(selected.length === 0);//审核通过
//            this.down('#' + this.oldId + "Back").setDisabled(selected.length === 0);//建议修改
//            this.down('#' + this.oldId + "AdjustTheQuota").setDisabled(selected.length === 0);//调整名额
            this.down('#' + this.oldId + "PostTrainingProgram").setDisabled(selected.length === 0);//发布培训计划
            this.down('#' + this.oldId + "Planplacesa").setDisabled(selected.length === 0);//下发培训计划
//            this.down('#' + this.oldId + "Importquotas").setDisabled(selected.length === 0);//批量更新培训计划
            this.down('#' + this.oldId + "trainingProgramAudit").setDisabled(selected.length === 0);//培训计划审核
            //this.down('#' + this.oldId + "Comparisons").setDisabled(selected.length === 0);//导出详情及名额
            //this.down('#' + this.oldId + "Trainingprogram").setDisabled(selected.length === 0);//导出培训计划
            //this.down('#' + this.oldId + "Summarycomments").setDisabled(selected.length === 0);//导出意见汇总表
		},
		viewready: function(){
			var me = this;
			//导出按钮集合
        	var exportMenu = Ext.create('Ext.menu.Menu', {
                items: [{
                    text: '培训班',
	        		iconCls: 'classIco',
	        		itemId: this.oldId + 'Trainingprogram',
	        		disabled: false,
                    listeners: {
                        click: function(btn){
                        	var records = me.getSelectionModel().getSelection();
                        	//me.ifSelect('class', me.store.exportTrainingUrl);
                        	if(records != null && records.length > 0){
                        		var classIdstr = "";
                                for(var i = 0;i<records.length;i++){
                                	if(i == records.length-1){
                                		classIdstr += "searchPlanIds=" + records[i].get("planId");
                                	}else{
                                		classIdstr += "searchPlanIds=" + records[i].get("planId") + "&";
                                	}
                                }
                                var atag = Ext.get("exportResume");
                                var exportUrl = me.store.exportTrainingUrl;
                                atag.set({
                                    "href": exportUrl + '?' + classIdstr
                                });
                                atag.dom.click();
                        	}else{
                        		var store = me.getStore();
                                var params=store.proxy.extraParams;
                                var href=store.exportTrainingUrl + "?";
                                for(var param in params){
                                	if(params[param] === undefined){
                                		href+="&"+param+"=";
                                	}else{
                                		href+="&"+param+"="+params[param];
                                	}
                                }
                                href = encodeURI(href);
                                var atag = Ext.get("exportResume");
                                atag.set({
                                    "href": href
                                });
                                atag.dom.click();
                        	}
                    	}
                    }
                }, {
                    text: '详情及名额',
	        		iconCls: 'comparisonsIco',
	        		itemId: this.oldId + 'Comparisons',
	        		disabled: false,
                    listeners: {
                    	click: function(btn){
                    		var records = me.getSelectionModel().getSelection();
                        	//var classId = Ext.isEmpty(record) ? "" : record[0].get("classId");
                        	//me.ifSelect('comparisons', me.store.contrastPlacesUrl, classId, 'searchClassId');
                    		if(records != null && records.length > 0){
                    			var classIdstr = "";
                                for(var i = 0;i<records.length;i++){
                                	if(i == records.length-1){
                                		classIdstr += "searchPlanIds=" + records[i].get("planId");
                                	}else{
                                		classIdstr += "searchPlanIds=" + records[i].get("planId") + "&";
                                	}
                                }
                                var atag = Ext.get("exportResume");
                                var exportUrl = me.store.contrastPlacesUrl;
                                atag.set({
                                    "href": exportUrl + '?' + classIdstr
                                });
                                atag.dom.click();
                    		}else{
                    			var store = me.getStore();
                                var params=store.proxy.extraParams;
                                var href=store.contrastPlacesUrl + "?";
                                for(var param in params){
                                	if(params[param] === undefined){
                                		href+="&"+param+"=";
                                	}else{
                                		href+="&"+param+"="+params[param];
                                	}
                                }
                                href = encodeURI(href);
                                var atag = Ext.get("exportResume");
                                atag.set({
                                    "href": href
                                });
                                atag.dom.click();
                    		}
                    	}
                    }
                }, {
                    text: '意见汇总表',
	        		iconCls: 'classDetailsIco',
	        		itemId: this.oldId + 'Summarycomments',
	        		disabled: false,
                    listeners: {
                    	click: function(btn){
                    		var records = me.getSelectionModel().getSelection();
                    		if(records != null && records.length > 0){
                    			var classIdstr = "";
                                for(var i = 0;i<records.length;i++){
                                	if(i == records.length-1){
                                		classIdstr += "searchPlanIds=" + records[i].get("planId");
                                	}else{
                                		classIdstr += "searchPlanIds=" + records[i].get("planId") + "&";
                                	}
                                }
                                var atag = Ext.get("exportResume");
                                var exportUrl = me.store.summaryCommentsUrl;
                                atag.set({
                                    "href": exportUrl + '?' + classIdstr
                                });
                                atag.dom.click();
                    		}else{
                    			var store = me.getStore();
                                var params=store.proxy.extraParams;
                                var href=store.summaryCommentsUrl + "?";
                                for(var param in params){
                                	if(params[param] === undefined){
                                		href+="&"+param+"=";
                                	}else{
                                		href+="&"+param+"="+params[param];
                                	}
                                }
                                href = encodeURI(href);
                                var atag = Ext.get("exportResume");
                                atag.set({
                                    "href": href
                                });
                                atag.dom.click();
                    		}
                    	}
                    }
                },{
                    text: '学员名额分配表',
	        		iconCls: 'comparisonsIco',
	        		itemId: this.oldId + 'Comparisons2',
	        		disabled: false,
                    listeners: {
                    	click: function(btn){
                    		var records = me.getSelectionModel().getSelection();
                        	//var classId = Ext.isEmpty(record) ? "" : record[0].get("classId");
                        	//me.ifSelect('comparisons', me.store.contrastPlacesUrl, classId, 'searchClassId');
                    		if(records != null && records.length > 0){
                    			var classIdstr = "";
                                for(var i = 0;i<records.length;i++){
                                	if(i == records.length-1){
                                		classIdstr += "searchPlanIds=" + records[i].get("planId");
                                	}else{
                                		classIdstr += "searchPlanIds=" + records[i].get("planId") + "&";
                                	}
                                }
                                var atag = Ext.get("exportResume");
                                var exportUrl = me.store.userExportUrl;
                                atag.set({
                                    "href": exportUrl + '?' + classIdstr
                                });
                                atag.dom.click();
                    		}else{
                    			var store = me.getStore();
                                var params=store.proxy.extraParams;
                                var href=store.userExportUrl + "?";
                                for(var param in params){
                                	if(params[param] === undefined){
                                		href+="&"+param+"=";
                                	}else{
                                		href+="&"+param+"="+params[param];
                                	}
                                }
                                href = encodeURI(href);
                                var atag = Ext.get("exportResume");
                                atag.set({
                                    "href": href
                                });
                                atag.dom.click();
                    		}
                    	}
                    }
                }]
            });
			this.addDocked([{
				dock: 'top',
				xtype: "searchform",
				columnCount: 3,
				fieldDefaults: {
					labelAlign: 'right',
					labelWidth: 100
				},
				items: [{
					xtype: "textfield",
					fieldLabel: '计划申请编号',
					name: "searchApplyNum",
					maxLength: "50",
					emptyText: "请输入计划编号"
				},{
					xtype: "textfield",
					fieldLabel: '培训班名称',
					name: "searchClassName",
					maxLength: "50",
					emptyText: "请输入培训班名称"
				},{
					xtype: "combo",
					fieldLabel: '审核状态',
					name: "searchAuditState",
					store: Ext.create("Ext.data.ArrayStore", {
						fields: ['value', 'text'],
						data: [[1, '审核通过'],[2,'建议修改'],[3,'待审核'],[5,'审核否决']]
					}),
					valueField: 'value',
					displayField: 'text',
					editable: false,
					emptyText: "请选择"
				},{
					xtype: "combo",
					fieldLabel: '下发状态',
					name: "searchIssuedState",
					store: Ext.create("Ext.data.ArrayStore", {
						fields: ['value', 'text'],
						data: [[1, '已下发'],[2,'未下发'],[3,'已反馈']]
					}),
					valueField: 'value',
					displayField: 'text',
					editable: false,
					emptyText: "请选择"
				},{
					xtype: "combo",
					fieldLabel: '发布状态',
					name: "searchPublishState",
					store: Ext.create("Ext.data.ArrayStore", {
						fields: ['value', 'text'],
						data: [[1, '已发布'],[2,'未发布']]
					}),
					valueField: 'value',
					displayField: 'text',
					editable: false,
					emptyText: "请选择"
				}],
				grid: this
			},{
				xtype: 'toolbar',
				dock: 'top',
				displayInfo: true,
				items: [/*this.updateButton, "-", */{
					text: '培训计划审核',
					iconCls: 'editIco',
					itemId: this.oldId + "trainingProgramAudit",
					disabled: true,
					scope: this,
					handler: this.onTrainingProgramAuditClick
				}/*, "-", {
					text: '建议修改',
					iconCls: 'backIco',
					itemId: this.oldId + "Back",
					disabled: true,
					scope: this,
					handler: this.onBackClick
				}, "-",{
                    text: '调整名额',
                    iconCls: 'adjustTheQuotaIco',
                    itemId: this.oldId + "AdjustTheQuota",
                    disabled: true,
                    scope: this,
                    handler: this.onAdjustTheQuotaClick
                }, "-",{
					text: '批量更新培训计划',
					iconCls: 'batchImportRegistrationIco',
					itemId: this.oldId + "Importquotas",
					disabled: true,
					scope: this,
					handler: this.onImportquotasClick
				}*/,"-", {
					text: '下发培训计划',
					iconCls: 'planplacesIco',
					itemId: this.oldId + "Planplacesa",
					disabled: true,
					scope: this,
					handler: this.onPlanplacesClick
				},"-", {
					text: '发布培训计划',
					iconCls: 'publishIco',
					itemId: this.oldId + "PostTrainingProgram",
					disabled: true,
					scope: this,
					handler: this.onPostTrainingProgramClick
				}, "-",{
					text: '导入培训班信息',
					iconCls: 'batchImportRegistrationIco',
					itemId: this.oldId + "importCourseInformation",
					disabled: false,
					scope: this,
					handler: this.onImportCourseInformationClick
				},"-",{
                    text: '导出',
                	xtype: 'button',
                    cls: 'floater',
                    textAlign: 'right',
                    arrowAlign: 'right',
                    itemId: this.oldId + 'Export',
                    enableToggle: true,
                    iconAlign: 'left',
                    iconCls: 'deriveIco',
                    pressedCls: 'x-btn-focus',
                    menuActiveCls: 'x-btn-menu-active',
                    menu: exportMenu
				},"->", this.countSelectPanel]
			}]);
            // 触发权限过滤事件
            me.fireEvent("permission", this);
		}
    }
});
